package com.randi.common.utils.secret;

import com.randi.common.core.domain.vo.SaltInfo;

import java.util.UUID;

/**
 * @author ziye
 */
public class SaltUtils {

    /**
     * 构建加密盐
     *
     * @return salt
     */
    public static SaltInfo buildSaltInfo() {
        // 生成UUID
        String uuid = UUID.randomUUID().toString().replace("-", "");
        // 随机截取生成加密盐
        StringBuilder salt = new StringBuilder();
        int maxLength = uuid.length();
        int saltLength = 16;
        for (int i = 0; i < saltLength; i++) {
            int random = (int) (Math.random() * maxLength);
            salt.append(uuid.charAt(random));
        }
        return new SaltInfo(salt.toString(), uuid);
    }

}
